package com.taotao.portal.service.ipml;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.taotao.common.pojo.TaotaoResult;
import com.taotao.common.utils.HttpClientUtil;
import com.taotao.common.utils.JsonUtils;
import com.taotao.domain.Order;
import com.taotao.portal.service.IOrderService;

@Service
public class OrderServiceIpml implements IOrderService {
	@Value("${ORDER_BASE_URL}")
	private String ORDER_BASE_URL;

	@Value("${ORDER_CREATE_URL}")
	private String ORDER_CREATE_URL;

	@Override
	public TaotaoResult createOrder(Order order) {
		// TODO Auto-generated method stub
		// 创建订单
		String orderJson = JsonUtils.objectToJson(order);
		String strJson = HttpClientUtil.doPostJson(ORDER_BASE_URL + ORDER_CREATE_URL, orderJson);
		if (StringUtils.isNotBlank(strJson)) {
			TaotaoResult taotaoResult = TaotaoResult.format(strJson);
			if (200 == taotaoResult.getStatus()) {
				return taotaoResult;
			}
		}
		return TaotaoResult.build(400, "创建订单失败");
	}

}
